#ifndef FILE_APPENDFILE_H
#define FILE_APPENDFILE_H

#include "utility/Noncopyable.h"

#include <array>
#include <string>

class AppendFile
{
public:
    explicit AppendFile(const std::string &filename);
    ~AppendFile();

    const std::string &filename() const { return _filename; }
    std::size_t written_bytes() const { return _writtenBytes; }

    void append(const char *buffer, std::size_t length);
    void flush();

private:
    NONCOPYABLE(AppendFile);

    std::size_t _write(const char * buffer, std::size_t length);
    std::array<char, 1 << 16> _buffer;
    const std::string _filename;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
    FILE *_stream;
#pragma GCC diagnostic pop
    std::size_t _writtenBytes;
};




#endif